<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #box{
      width: 100px;
      height: 100px;
      background-color: #784;
      /* transition: transform 1s; */
    }
  </style>
</head>
<body>
  <button id="btn">按钮</button>
  <div id="box"></div>
  <script>
    let box=document.getElementById('box')
    let btn=document.getElementById('btn')
    let dest=window.innerWidth-500;
    let requestAnimationFrame=window.requestAnimationFrame;
    let speed=1;
    let position=0;
    btn.onclick=function(){
      requestAnimationFrame(step)
    }
    function move(el,position){
      box.style.transform=`translate3d(${position}px,0,0)`
    }
    function step(){
      if(position<dest){
        position+=speed;
        move(box,position)
        requestAnimationFrame(step)
      }else{
        position=dest;
        move(box,position)
      }
    }
  </script>
</body>
</html>